import re
import datetime
from datetime import timedelta
num =re.compile(r'\d+')

def get_num(a):
    pat = re.compile(r'(\d+).+?(\d+)' or r'.+?(\d+).+?(\d+)')
    data = pat.findall(a)[0]
    return data[0],data[1]



def get_time(a):
    if '天前' in a :
        res = num.search(a).group()
        date_pub = (datetime.datetime.now() - timedelta(days=int(res))).strftime('%Y-%m-%d')
    else:
        date_pub = datetime.datetime.now().strftime('%Y-%m-%d')
    return date_pub

def work_year(a):
    if '-' in a:
        syear,eyear = get_num(a)

    elif '以上' in a :
        res = num.search(a)
        syear = res.group()
        eyear = res.group()
    else:
        syear = 0
        eyear =0
    return syear, eyear